package com.yxhl.zoume.navigator;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.view.View;

import com.yxhl.protobuf.BizOrder;
import com.yxhl.protobuf.BizOrderResponse;
import com.yxhl.protobuf.OneYxBusInfoRequest;
import com.yxhl.protobuf.OrderBizType;
import com.yxhl.protobuf.ScheduleType;
import com.yxhl.protobuf.StationEntry;
import com.yxhl.zoume.R;
import com.yxhl.zoume.UIConstants;
import com.yxhl.zoume.account.activity.MobileLoginActivity;
import com.yxhl.zoume.common.ui.activity.AddPassengerActivity;
import com.yxhl.zoume.common.ui.activity.AdvertisementActivity;
import com.yxhl.zoume.common.ui.activity.ZMCalendarActivity;
import com.yxhl.zoume.core.busticket.model.TicketsQueryOptions;
import com.yxhl.zoume.core.busticket.ui.activity.BusServicesQueryActivity;
import com.yxhl.zoume.core.busticket.ui.activity.BusStationsListActivity;
import com.yxhl.zoume.core.busticket.ui.activity.BusTicketOrderActivity;
import com.yxhl.zoume.core.busticket.ui.activity.ZouMeBusOrderActivity;
import com.yxhl.zoume.core.car.activity.CarLocationMapActivity;
import com.yxhl.zoume.core.car.activity.CarPricingRulesActivity;
import com.yxhl.zoume.core.coupon.activity.CouponActivity;
import com.yxhl.zoume.core.coupon.activity.CouponSelectActivity;
import com.yxhl.zoume.core.coupon.model.CouponSelectModel;
import com.yxhl.zoume.core.expresscar.activity.ExpressCarContainerActivity;
import com.yxhl.zoume.core.expresscar.activity.ExpressCarScheduleActivity;
import com.yxhl.zoume.core.func.appraisal.model.AppraisalDriverInfo;
import com.yxhl.zoume.core.func.appraisal.ui.activity.AppraisalActivity;
import com.yxhl.zoume.core.func.appraisal.ui.activity.AppraisalConfirmActivity;
import com.yxhl.zoume.core.func.map.ui.activity.LocationMapActivity;
import com.yxhl.zoume.core.func.passenger.ui.MultipleSelectType;
import com.yxhl.zoume.core.func.passenger.ui.PsgerItemType;
import com.yxhl.zoume.core.func.passenger.ui.SelectPsgersActivity;
import com.yxhl.zoume.core.func.pay.activity.BusPaymentActivity;
import com.yxhl.zoume.core.func.pay.activity.CarPaymentActivity;
import com.yxhl.zoume.core.func.push.model.PushMessage;
import com.yxhl.zoume.core.func.webpage.activity.WebPageActivity;
import com.yxhl.zoume.core.func.webpage.info.WebPageEntrance;
import com.yxhl.zoume.core.main.model.MainEntranceInfo;
import com.yxhl.zoume.core.main.ui.MainActivity;
import com.yxhl.zoume.core.officialcar.activity.CallCarForOthersActivity;
import com.yxhl.zoume.core.officialcar.activity.OfficialCarContainerActivity;
import com.yxhl.zoume.core.officialcar.activity.OfficialCarScheduleActivity;
import com.yxhl.zoume.core.specialcar.activity.PassengerNoticeActivity;
import com.yxhl.zoume.core.specialcar.activity.SpecialCarContainerActivity;
import com.yxhl.zoume.core.specialcar.activity.SpecialCarFeeDetailActivity;
import com.yxhl.zoume.core.specialcar.activity.SpecialCarOrderCancelActivity;
import com.yxhl.zoume.core.specialcar.activity.SpecialCarScheduleActivity;
import com.yxhl.zoume.core.specialcar.model.CarLocationMapEntrance;
import com.yxhl.zoume.core.specialcar.model.CarPaymentInfo;
import com.yxhl.zoume.core.specialcar.model.SpecialCarContainerActivityParam;
import com.yxhl.zoume.core.specialcar.model.SpecialCarFeeDetailModel;
import com.yxhl.zoume.core.tripsmgmt.info.CommentEntrance;
import com.yxhl.zoume.core.tripsmgmt.info.LocationMapEntrance;
import com.yxhl.zoume.core.tripsmgmt.info.ZouMeBusMapEntrance;
import com.yxhl.zoume.core.tripsmgmt.ui.activity.BusMapContainerActivity;
import com.yxhl.zoume.core.tripsmgmt.ui.activity.BusTicketRefundProgressActivity;
import com.yxhl.zoume.core.tripsmgmt.ui.activity.CommentOnDriverActivity;
import com.yxhl.zoume.core.tripsmgmt.ui.activity.TicketCodeActivity;
import com.yxhl.zoume.core.tripsmgmt.ui.activity.TripDetailContainerActivity;
import com.yxhl.zoume.core.user.ui.activity.MyWalletActivity;
import com.yxhl.zoume.core.user.ui.activity.MyWalletDetailActivity;
import com.yxhl.zoume.core.user.ui.activity.NameIdentificationActivity;
import com.yxhl.zoume.core.user.ui.activity.UserContainerActivity;
import com.yxhl.zoume.core.user.ui.info.UserCenterPageEnum;
import com.yxhl.zoume.data.http.model.busticket.ZMBusTicketOrder;
import com.yxhl.zoume.data.http.model.mywallet.TradeRecordBean;
import com.yxhl.zoume.data.http.model.passenger.ZMPassenger;

import java.io.Serializable;
import java.util.List;

import javax.inject.Inject;
import javax.inject.Singleton;

/**
 * Created by Xboy on 16/3/16.
 */

@Singleton
public class Navigator {

    @Inject
    public Navigator() {
    }

    /**
     * 跳转到主页
     *
     * @param activity
     */
    public void navigateToMain(@NonNull Activity activity, MainEntranceInfo mainEntranceInfo) {
        Intent intent = MainActivity.getCallingIntent(activity, mainEntranceInfo);
        activity.startActivity(intent);
    }


    /**
     * 跳转到快车页面
     *
     * @param activity
     * @param activityParam
     */
    public void navigateToSpecialCarContainerActivity(@NonNull Activity activity, SpecialCarContainerActivityParam activityParam) {
        Intent intent = SpecialCarContainerActivity.getCallingIntent(activity, activityParam);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.noanimation);
    }

    /**
     * 跳转到公务车页面
     *
     * @param activity
     */
    public void navigateToOfficialCarContainerActivity(@NonNull Activity activity) {
        Intent intent = OfficialCarContainerActivity.getCallingIntent(activity);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.noanimation);
    }

    public void navigateToCallCarForOthersActivity(@NonNull Activity activity) {
        Intent intent = CallCarForOthersActivity.getCallingIntent(activity);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.noanimation);
    }


    /**
     * 跳转到快速登录页面
     *
     * @param context
     */
    public void navigateToMobileLogin(@NonNull Context context) {
        Intent intent = MobileLoginActivity.getCallingIntent(context);
        context.startActivity(intent);
    }

    /**
     * 跳转到车票查询结果页面
     * by Xboy
     *
     * @param context
     * @param options
     */
    public void navigateToBusServicesList(@NonNull Context context,
                                          TicketsQueryOptions options) {
        Intent intentToTicketList = BusServicesQueryActivity.getCallingIntent(context, options);
        context.startActivity(intentToTicketList);
    }


    /**
     * 跳转到车票订单页面
     * by Xboy
     *
     * @param context
     * @param param
     */
    public void navigateToBusTicketOrder(@NonNull Context context, OneYxBusInfoRequest param, ScheduleType scheduleType) {
        Intent intentToTicketOrder = BusTicketOrderActivity.getCallingIntent(context, param, scheduleType);
        context.startActivity(intentToTicketOrder);
    }

    /**
     * 跳转到定制巴士订单页面
     * by Xboy
     *
     * @param context
     * @param param
     */
    public void navigateToZouMeBusOrder(@NonNull Context context, OneYxBusInfoRequest param) {
        Intent intentToZouMeBusOrder = ZouMeBusOrderActivity.getCallingIntent(context, param);
        context.startActivity(intentToZouMeBusOrder);
    }

    /**
     * 跳转到巴士搜索车站列表页
     * author vhawk
     *
     * @param context
     * @param selectStartCityEntity 出发站，此参数为null，到达站，此参数传出发站的车站信息
     */
    public void navigateToStationsList(@NonNull Context context, Serializable selectStartCityEntity) {
        Intent intent = BusStationsListActivity.getCallingIntent(context, selectStartCityEntity);
        context.startActivity(intent);
    }

    /**
     * 跳转到日历界面
     * by Xboy
     *
     * @param context
     */
    public void navigateToCalendar(@NonNull Context context) {
        Intent intent = new Intent(context, ZMCalendarActivity.class);
        context.startActivity(intent);
    }

    /**
     * 跳转支付页面
     * 适用定制巴士、固定时刻类巴士
     *
     * @param context
     * @param order
     */
    public void navigateToPayment(@NonNull Context context, BizOrder order) {
        Intent intent = BusPaymentActivity.getCallingIntent(context, order);
        context.startActivity(intent);
    }

    /**
     * 跳转支付页面
     * 巴士模块下,非定制巴士下单,跳转到支付页面
     *
     * @param context
     * @param order
     */
    public void navigateToPayment(@NonNull Context context, ZMBusTicketOrder order) {
        Intent intent = BusPaymentActivity.getCallingIntent(context, order);
        context.startActivity(intent);
    }

    /**
     * 跳转到行程详情页
     * Ethan
     *
     * @param activity
     * @param shareView
     * @param bizOrder
     */
    public void navigateToDetailTripContainerActivity(@NonNull Activity activity, View shareView, BizOrder bizOrder) {
        Intent launch = TripDetailContainerActivity.getCallingIntent(activity, bizOrder);
        try {
            ActivityOptionsCompat optionsCompat = ActivityOptionsCompat
                    .makeSceneTransitionAnimation(activity, shareView, UIConstants.TripContainer.TRIP_DETAIL_SHARE_ELEMENT);

            ActivityCompat.startActivity(activity, launch, optionsCompat.toBundle());
        } catch (Exception e) {
            activity.startActivity(launch);
        }
    }

    public void navigateToDetailTripContainerActivity(@NonNull Activity activity, PushMessage pushMessage) {
        Intent launch = TripDetailContainerActivity.getCallingIntent(activity, pushMessage);
        activity.startActivity(launch);
    }

    /**
     * 跳转到 我的车票
     * Ethan
     *
     * @param activity
     * @param orderSerial
     */
    public void navigateToTicketCodeActivity(@NonNull Activity activity, @NonNull String orderSerial, OrderBizType bizType) {
        if (activity != null) {
            Intent launch = TicketCodeActivity.getCallingIntent(activity, orderSerial, bizType);
            activity.startActivity(launch);
            activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
        }
    }


    /**
     * 跳转到选择乘车人
     * by Xboy
     *
     * @param context
     * @param selectedPassengers
     */
    public void navigateToSelectPassengers(@NonNull Context context, List<ZMPassenger> selectedPassengers, PsgerItemType itemType) {
        Intent intentToSelectPassengers = SelectPsgersActivity.getCallingIntent(context, selectedPassengers, itemType);
        context.startActivity(intentToSelectPassengers);
    }

    /**
     * 跳转到选择乘车人
     * by Xboy
     *
     * @param context
     * @param selectedPassengers
     */
    public void navigateToSelectPassengers(@NonNull Context context, List<ZMPassenger> selectedPassengers, PsgerItemType itemType, MultipleSelectType multipleSelectType) {
        Intent intentToSelectPassengers = SelectPsgersActivity.getCallingIntent(context, selectedPassengers, itemType, multipleSelectType);
        context.startActivity(intentToSelectPassengers);
    }

    /**
     * 跳转到乘客管理界面(用户中心)
     *
     * @param activity
     * @param directionFla
     */
    public void navigateToPassengerManagement(@NonNull Activity activity, UserCenterPageEnum directionFla) {
        if (activity != null) {
            Intent launch = UserContainerActivity.getCallingIntent(activity, directionFla);
            activity.startActivity(launch);
            activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
        }
    }

    public void navigateToAddPassengerActivity(@NonNull Activity activity) {
        if (activity != null) {
            Intent launch = AddPassengerActivity.getCallingIntent(activity);
            activity.startActivity(launch);
            activity.overridePendingTransition(R.anim.right_enter, R.anim.noanimation);
        }
    }

    /**
     * 跳转到选择地点地图页面
     *
     * @param activity
     * @param entrance
     */
    public void navigateToLocationMapActivity(@NonNull Activity activity, LocationMapEntrance entrance) {
        if (activity != null) {
            Intent launch = LocationMapActivity.getCallingIntent(activity, entrance);
            activity.startActivity(launch);
            activity.overridePendingTransition(R.anim.right_enter, R.anim.noanimation);
        }
    }

    public void navigateToSpecialCarScheduleActivity(@NonNull Activity activity, String specialCarOrderId) {
        if (activity != null) {
            Intent launch = SpecialCarScheduleActivity.getCallingIntent(activity, specialCarOrderId);
            activity.startActivity(launch);
            activity.overridePendingTransition(R.anim.right_enter, R.anim.noanimation);
        }
    }


    /**
     * 全局通用静态页面说明页
     *
     * @param activity
     * @param entrance 全局静态页管理类
     */
    public void navigateToWebPageActivity(@NonNull Activity activity, @NonNull WebPageEntrance entrance) {
        Intent intent = WebPageActivity.getCallingIntent(activity, entrance);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 跳转到帮助中心
     *
     * @param activity
     * @param pageEnum
     */
    public void navigateToHelpCenter(@NonNull Activity activity, @NonNull UserCenterPageEnum pageEnum) {
        Intent intent = UserContainerActivity.getCallingIntent(activity, pageEnum);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 实名认证
     *
     * @param activity
     */
    public void navigateToNameIdentification(@NonNull Activity activity) {
        Intent intent = NameIdentificationActivity.getCallingIntent(activity);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 乘客通知
     *
     * @param activity
     */
    public void navigateToPassengerNoticeActivity(Activity activity) {
        Intent intent = PassengerNoticeActivity.getCallingIntent(activity);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.noanimation);
    }

    /**
     * 评价司机页
     *
     * @param activity
     * @param bizOrder
     * @param commentEntrance
     */
    public void navigateToCommentOnDriverActivity(Activity activity, BizOrder bizOrder, CommentEntrance commentEntrance) {
        Intent intent = CommentOnDriverActivity.getCallingIntent(activity, bizOrder, commentEntrance);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }


    /**
     * 跳转到定制巴士相关地图
     *
     * @param activity
     * @param entrance
     */
    public void navigateToZouMeBusMapContainerActivity(@NonNull Activity activity, List<StationEntry> upPoints, ZouMeBusMapEntrance entrance) {
        Intent intent = BusMapContainerActivity.getCallingIntent(activity, upPoints, entrance);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    public void navigateToZouMeBusMapContainerActivity(@NonNull Activity activity, BizOrderResponse bizOrderResponse, ZouMeBusMapEntrance entrance) {
        Intent intent = BusMapContainerActivity.getCallingIntent(activity, bizOrderResponse, entrance);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }


    /**
     * 跳转到公务车下单地图页
     *
     * @param activity
     * @param orderId
     */
    public void navigateToOfficialCarScheduleActivity(@NonNull Activity activity, String orderId) {
        Intent intent = OfficialCarScheduleActivity.getCallingIntent(activity, orderId);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 跳转到专车
     *
     * @param activity
     */
    public void navigateToExpressCarContainerActivity(@NonNull Activity activity) {
        Intent intent = ExpressCarContainerActivity.getCallingIntent(activity);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 跳转到专车下单地图页
     *
     * @param activity
     */
    public void navigateToExpressCarScheduleActivity(@NonNull Activity activity, String orderId) {
        Intent intent = ExpressCarScheduleActivity.getCallingIntent(activity,orderId);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 跳转地点选择页面
     *
     * @param activity
     * @param entrance
     */
    public void navigateToCarLoactionMapSelectActivity(@NonNull Activity activity, CarLocationMapEntrance entrance) {
        Intent intent = CarLocationMapActivity.getCallingIntent(activity, entrance);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 跳转到司机评论模块
     *
     * @param activity
     * @param driverInfo
     */
    public void navigateToAppraisal(Activity activity, AppraisalDriverInfo driverInfo) {
        Intent intent = AppraisalActivity.getCallingIntent(activity, driverInfo);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 跳转到评论结果页面
     *
     * @param activity   用于初始化 Intent和控制页面跳转
     * @param driverInfo 待评价司机基本信息，评价模块入参
     */
    public void navigateToAppraisalResult(Activity activity, AppraisalDriverInfo driverInfo) {
        Intent intent = AppraisalConfirmActivity.getCallingIntent(activity, driverInfo);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }


    /**
     * 跳转快车支付页面
     *
     * @param activity    用于初始化 Intent和控制页面跳转
     * @param paymentInfo 快车支付基本信息，部分信息用于评价模块
     */
    public void navigateToSpecialCarPayment(Activity activity, CarPaymentInfo paymentInfo) {
        Intent intent = CarPaymentActivity.getCallingIntent(activity, paymentInfo);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }


    /**
     * 跳转快车取消任务
     *
     * @param activity
     * @param orderId
     */
    public void navigateToSpecialCarOrderCancel(Activity activity, String orderId) {
        Intent intent = SpecialCarOrderCancelActivity.getCallingIntent(activity, orderId);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }


    /**
     * 跳转到广告页
     *
     * @param activity
     * @param Url
     */
    public void navigateToAdActivity(Activity activity, String Url) {
        Intent intent = AdvertisementActivity.getCallingIntent(activity, Url);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 优惠券 个人中心进入
     *
     * @param activity
     */
    public void navigateToCoupon(Activity activity) {
        Intent intent = CouponActivity.getCallingIntent(activity);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 跳转到反馈
     *
     * @param activity
     * @param pageEnum
     */
    public void navigateToFeedback(@NonNull Activity activity, @NonNull UserCenterPageEnum pageEnum) {
        Intent intent = UserContainerActivity.getCallingIntent(activity, pageEnum);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }


    /**
     * 跳转到更多
     *
     * @param activity
     * @param pageEnum
     */
    public void navigateToMore(@NonNull Activity activity, @NonNull UserCenterPageEnum pageEnum) {
        Intent intent = UserContainerActivity.getCallingIntent(activity, pageEnum);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 我的钱包
     *
     * @param activity
     */
    public void navigateToMyWallet(Activity activity) {
        Intent intent = MyWalletActivity.getCallingIntent(activity);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 收支详情
     *
     * @param activity
     */
    public void navigateToIncomeExpensesDetail(Activity activity, TradeRecordBean tradeRecordBean) {
        Intent intent = MyWalletDetailActivity.getCallingIntent(activity, tradeRecordBean);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }


    /**
     * 跳转到选择优惠券
     *
     * @param activity
     * @param couponSelectModel
     */
    public void navigateToCouponSelectPage(Activity activity, CouponSelectModel couponSelectModel) {
        Intent intent = CouponSelectActivity.getCallingIntent(activity, couponSelectModel);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 跳转到快车行程费用明细
     *
     * @param activity
     * @param specialCarFeeDetailModel
     */
    public void navigateToSpecialCarPayDetail(Activity activity, SpecialCarFeeDetailModel specialCarFeeDetailModel) {
        Intent intent = SpecialCarFeeDetailActivity.getCallingIntent(activity, specialCarFeeDetailModel);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 跳转到计价规则
     * @param activity
     * @param bizType
     * @param vehicleType
     * @param partTime
     */
    public void navigateToCarPricingRulesActivity(Activity activity, OrderBizType bizType, String vehicleType, int partTime){
        Intent callingIntent = CarPricingRulesActivity.getCallingIntent(activity, bizType, vehicleType, partTime);
        activity.startActivity(callingIntent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

    /**
     * 退款详情
     * @param activity
     * @param order
     */
    public void navigateToBusRefundProcessActicity(Activity activity, String order){
        Intent intent = BusTicketRefundProgressActivity.getCallingIntent(activity, order);
        activity.startActivity(intent);
        activity.overridePendingTransition(R.anim.right_enter, R.anim.left_out);
    }

}
